package com.ywgt.controller;

import com.ywgt.pojo.Permission;
import com.ywgt.pojo.Role;
import com.ywgt.service.PermissionService;
import com.ywgt.service.RoleService;
import com.ywgt.util.ResponseUtil;
import io.swagger.annotations.ApiModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.stream.Collectors;

@CrossOrigin
@RestController
@RequestMapping("/admin/auth")
@ApiModel("管理员认证")
public class AuthController {

    @Autowired
    RoleService roleService;

    @Autowired
    PermissionService permissionService;

    @PostMapping("/login")
    public Object login(String username,String password){
        return ResponseUtil.ok("123456");
    }

    @GetMapping("/info")
    public Object info(){
        List<Permission> permissions = permissionService.list();
//        List<Role> roles = roleService.list();
        List<Role> roles = roleService.getAll();

        Map<String,Object> data=new HashMap<>();
        data.put("name","蔡徐坤");
        data.put("avator","https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKchov541UonxDIB7yicvCWKToIQTEDibACkMpBjj7U0uibRibaMKdEUQwQ8dciaSO7cVL3ojglNhFLP5w/132");
        List<String> roleList = roles.stream().map(a -> a.getName()).collect(Collectors.toList());
        Set<String> perms = permissions.stream().map(a -> a.getPermission()).collect(Collectors.toSet());
        data.put("roles",roleList);
        data.put("perms","*");
        return ResponseUtil.ok(data);
    }

}
